package com.hnkywl.sts.service.tjbb;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hnkywl.sts.dao.tjbb.ZjzyDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: SDE09
 * Date: 13-9-28
 * Time: 下午5:13
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ZjzyService {
    private ZjzyDao zjzyDao;

    public String zjzyList(Integer gsid, Date enddt, Integer type, Integer tc_flag) {
        Map<String, List> result = zjzyDao.zjzyList(gsid, enddt, type, tc_flag);
        List<Map> rows = result.get("rows");
        List<Map> footer = result.get("footer");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String footerJson = gson.toJson(footer);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson + "}";
        return json;
    }

    /**
     * 库存金额
     *
     * @param gsid
     * @param type
     * @param enddt
     * @return
     */
    public String bgkcje(Integer gsid, Integer type, Date enddt, Integer tc_flag, Integer pageNo, Integer pageSize) {
        Map<String, Object> result = zjzyDao.bgkcjeList(gsid, type, enddt, tc_flag, pageNo, pageSize);
        Integer total=(Integer)result.get("total");
        List<Map> rows = (List<Map>) result.get("rows");
        List<Map> footer = (List<Map>) result.get("footer");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String footerJson = gson.toJson(footer);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson +",\"total\":"+total+  "}";
        return json;
    }

    /**
     * 在途资金
     *
     * @param gsid
     * @param type
     * @param enddt
     * @param tc_flag
     * @return
     */
    public String bqztzj(Integer gsid, Integer type, Date enddt, Integer tc_flag) {
        List<Map> list = zjzyDao.findbqztzj(gsid, type, enddt, tc_flag);
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
        String json = gson.toJson(list);
        return "{\"rows\":" + json + "}";
    }

    //付款
    public String bgyufk(Integer gsid, Date enddt, Integer type, Integer tc_flag) {
        Map<String, List> result = zjzyDao.bgyufkList(gsid, enddt, type, tc_flag);
        List<Map> rows = result.get("rows");
        List<Map> footer = result.get("footer");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String footerJson = gson.toJson(footer);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson + "}";
        return json;
    }

    //收款
    public String bgyingsk(Integer gsid, Date enddt, Integer type, Integer tc_flag) {
        Map<String, List> result = zjzyDao.bgyingskList(gsid, enddt, type, tc_flag);
        List<Map> rows = result.get("rows");
        List<Map> footer = result.get("footer");
        Gson gson = new GsonBuilder().create();
        String rowsJson = gson.toJson(rows);
        String footerJson = gson.toJson(footer);
        String json = "{\"rows\":" + rowsJson + ",\"footer\":" + footerJson + "}";
        return json;
    }

    @Autowired
    public void setZjzyDao(ZjzyDao zjzyDao) {
        this.zjzyDao = zjzyDao;
    }
}
